<?
/***************************************************************************
Jupiter Content System @ Jupiterportal.org
 
Copyright (C) 2005-2007 Cosmin Flavius (highstrike@gmail.com)
Copyright (C) 2008-2009 George Mark (gmark@jupiterportal.org)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU 
General Public License as published by the Free Software Foundation; either version 3 of the License, 
or (at your option) any later version.

More Info About The License At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

function b_who()
{
	$name_function = "b_who";

	global $a, $db, $blocks_db, $template, $language, $config, $misc, $PHP_SELF, $is_loged_in, $is_moderator, $is_administrator, $is_webmaster, $months, $days, $m, $y, $OnlineGuestsCount, $OnlineMembersCount;
	if(!file_exists("blocks/$name_function/language/{$config['language']}")) include "blocks/$name_function/language/en.php";
	else include "blocks/$name_function/language/{$config['language']}";

	$random_code = md5("$name_function");
	$random_code = substr("$random_code", 0, 5);

	if(!isset($content)) $content = NULL;
	if(!isset($_GET["$random_code"])) $_GET["$random_code"] = NULL;

	if($_GET["$random_code"] == "on") $_SESSION["$random_code"] = "on";
	elseif($_GET["$random_code"] == "off") $_SESSION["$random_code"] = "off";

	$query_string = "?{$_SERVER['QUERY_STRING']}";

	foreach($blocks_db as $blocks)
	{
		$block_code = md5("{$blocks['name']}");
		$block_code = substr("$block_code", 0, 5);

		$query_string = str_replace("&$block_code=off","", $query_string);
		$query_string = str_replace("&$block_code=on","", $query_string);
	}

	if($query_string == "?" || strpos($query_string, '=on') !== false || strpos($query_string, '=off') !== false) $code_query = "?";
	else $code_query = "$query_string&";

	if(!isset($_SESSION["$random_code"]) || $_SESSION["$random_code"] == "on") $links = "<a href='$code_query$random_code=off'><img src='templates/$template/images/misc/minus.gif' border='0'> {$language_block['Who title']}</a>";
	elseif($_SESSION["$random_code"] == "off") $links = "<a href='$code_query$random_code=on'><img src='templates/$template/images/misc/plus.gif' border='0'> {$language_block['Who title']}</a>";

	$template_block = implode("", file("templates/$template/block.php"));
	$template_block = str_replace("{template}", $template, $template_block);
	$template_block = str_replace("{links}", $links, $template_block);

	if(!isset($_SESSION["$random_code"]) || $_SESSION["$random_code"] == "on")
	{
		//-----------------------------------------------------------------
		//  Load Live Members Table
		//-----------------------------------------------------------------

		$members = $db->getTable("SELECT user_id, user, user_authorization FROM online WHERE type = 'live' AND status = 'member'");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		if($members != FALSE)
		{
			$content .= "<tr><td class='con1'>";

			foreach($members as $idx=>$member)
			{
				If($member['user_authorization'] == 4) $color = "blue";
				If($member['user_authorization'] == 3) $color = "red";
				If($member['user_authorization'] == 2) $color = "green";
				If($member['user_authorization'] == 1) $color = "#606060";
				
				$content .= "<a href='$PHP_SELF?n=modules/users&a=1&d={$member['user_id']}' title='".find_authorization($member['user_authorization'])."'><font style='font-weight:normal' color='$color'><img src='templates/$template/images/authorization/{$member['user_authorization']}.gif' border='0' alt='".find_authorization($member['user_authorization'])."'> {$member['user']}</font></a>, ";
			}

			$content .= "end of coma</td></tr>";

			$content = str_replace(', end of coma', "", $content);
		}
		else $content = "<tr><td class='con1'>{$language_block['Who desc']}</td></tr>";
}

	$template_block = str_replace("{content}", $content, $template_block);
	$output = $template_block;

return $output;
}

?>